function qs(ele) {
    return document.querySelector(ele)
}

// 接口地址：https://www.apifox.cn/apidoc/shared-36f0cbc0-9064-44bc-850a-805e263bf494/api-25827426
axios.defaults.baseURL='http://124.223.14.236:3001/api'

async function getchenData(){
    const {data:res}=await axios.get('/city/province')
    console.log(res);
    const provinceStr = res.data.map(
        item => `<option value="${item.province}">${item.name}</option>`)
    .join('')
    qs('#province').innerHTML='<option value="">请选择省份</option>'+provinceStr

}
async function getshiData(provinceCode){
    const {data:{data:ctry1}} = await axios.get('/city/city',{
        params:{
            provinceCode
        }  
    })
    const ctry2 = ctry1.map((item)=> `<option value="${item.city}">${item.name}</option>`).join('')
    qs('#city').innerHTML =`<option value="">请选择城市</option>`+ctry2
    
}
async function getquData(provinceCode,cityCode){
    const {data:{data:areaData}}=await axios.get('/city/area', {
        params:{
            provinceCode,
            cityCode
        }
    })
    const ququ = areaData.map(
        (item)=> `<option value="${item.area}">${item.name}</option>`
    ).join('')
    qs('#county').innerHTML = `<option value="">请选择区县</option>`+ququ
    
}

getchenData()



    //===============省选择==============
    
//==========市区选择===========

//==========县选择===========


// =========当省改变时市区的变化==========
qs('#province').addEventListener('change',async function(){
    getshiData(this.value)
})
//=========当市区改变时，县发生的改变==========
qs('#city').addEventListener('change',async function(){
    getquData(qs('#province').value,this.value)
})